<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/file-upload.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/form/FileUploadField.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript" src="../../scripts/imageViewer.js"></script>
        <script type="text/javascript">
            var armorMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.armor');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			
			var ctArmorTypeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtArmorType');
			var ctArmor1TypeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtArmor1Type');
			var ctArmorSetXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtArmorSet');
			var ctJaugeXmlLoader = new xmlLoader('../../servlet/CodeTableServlet?name=CtJauge');
            
			var ctArmorTypeStore;
			var ctArmor1TypeStore;
			var ctArmorSetStore;
			var ctJaugeStore;
			
			var ctArmorTypeCombo;
			var ctArmor1TypeCombo;
			var ctArmorSetCombo;
			var ctJaugeCombo;
			
			var setReference = function(){
				if(getPrarmeterValue(window.location, 'id') != null) return;
				if(ctArmorTypeCombo.getValue() == '' || ctJaugeCombo.getValue() == ''){
					return;
				}
				var armor = ctArmorTypeCombo.getRawValue();
				var jauge = ctJaugeCombo.getRawValue();
				var maxReferenceIndextXmlLoader = new xmlLoader('../../servlet/BiArmorServlet?action=10&ctArmorType=' + ctArmorTypeCombo.getValue() + '&ctJauge=' + ctJaugeCombo.getValue());
				var maxIndex = maxReferenceIndextXmlLoader.getValueByTagName('item');
				//alert(maxIndex);
				document.getElementById('referenceIndex').value = maxIndex;
				document.getElementById('reference').value = 'W-' + armor.substring(armor.indexOf('=')+2) + '-G' + jauge + '-' + maxIndex;
			}
			
			var setDescriptoin = function(){
				if(ctArmorTypeCombo.getValue() == '' || ctArmor1TypeCombo.getValue() == '' || ctArmorSetCombo.getValue() == ''){
					return;
				}
				var armor = ctArmorTypeCombo.getRawValue();
				Ext.getCmp('description').setValue(armor.substring(0, armor.indexOf('=')-1) + ' ' + ctArmor1TypeCombo.getRawValue() + ' ' + ctArmorSetCombo.getRawValue());
			}
			
            Ext.onReady(function(){
                Ext.QuickTips.init();
                
                Ext.form.Field.prototype.msgTarget = 'side';
                
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
                
                var idValue = getPrarmeterValue(window.location, 'id');
                var startPage = getPrarmeterValue(window.location, 'startPage');
				
				ctArmorTypeStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctArmorTypeXmlLoader.getXml()
                });

				ctArmor1TypeStore = new Ext.data.Store({
	                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctArmor1TypeXmlLoader.getXml()
                });
				
				ctArmorSetStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctArmorSetXmlLoader.getXml()
                });
				
				ctJaugeStore = new Ext.data.Store({
                   
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'code',
                        totalRecords: 'itemTotal'
                    }, [
                    'code', 'description']),
					data: ctJaugeXmlLoader.getXml()
                });
				
				ctArmorTypeCombo = new Ext.form.ComboBox({
					fieldLabel: armorMessage.get('ui.armor.type'),
					id: 'ctArmorType',
					name: 'ctArmorType',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					valueField: 'code',
				    store: ctArmorTypeStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
				    anchor: '90%',
					mode: 'local',
					listeners: {
						select: {
							fn: function (thisCombo, record,index){
								ctArmor1TypeCombo.reset();
								ctArmor1TypeStore.loadData(ctArmor1TypeXmlLoader.getXml());

								ctArmorSetCombo.reset();
								ctArmorSetStore.loadData(ctArmorSetXmlLoader.getXml());
								
								var length = ctArmor1TypeStore.getCount();
								if(thisCombo.getValue() == '01'){
									for(var i = length; i > 5; i--){
										ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(ctArmor1TypeStore.getCount()-1));
									}

									ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
									ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
								}else if(thisCombo.getValue() == '02'){
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(ctArmor1TypeStore.getCount()-2));//菜单联动，去掉多余的项，没什么规律，所以代码写死。
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(ctArmor1TypeStore.getCount()-2));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(ctArmor1TypeStore.getCount()-2));

									ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
									ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
								}else{
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(0));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(10));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(10));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(10));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(10));
									ctArmor1TypeStore.remove(ctArmor1TypeStore.getAt(13));
								}
								setReference();
								setDescriptoin();
							}
						}
					}
				});

				ctArmor1TypeCombo = new Ext.form.ComboBox({
					fieldLabel: armorMessage.get('ui.armor.type'),
					id: 'ctArmor1Type',
					name: 'ctArmor1Type',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					hideLabel: true,
					valueField: 'code',
				    store: ctArmor1TypeStore,
				    displayField:'description',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					anchor: '92%',
					listeners: {
						select: {
							fn: function (thisCombo, record,index){
								if(thisCombo.getValue() == '16' || thisCombo.getValue() == '17'){
									Ext.getCmp('armorTypeE').enable();
								}else{
									Ext.getCmp('armorTypeE').disable();
								}
								if(ctArmorTypeCombo.getValue() == '03'){
									ctArmorSetCombo.reset();
									ctArmorSetStore.loadData(ctArmorSetXmlLoader.getXml());
									if(ctArmor1TypeCombo.getValue() == '04' || ctArmor1TypeCombo.getValue() == '05' || ctArmor1TypeCombo.getValue() == '06'){
										ctArmorSetStore.remove(ctArmorSetStore.getAt(3));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(3));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(3));
									}else if(ctArmor1TypeCombo.getValue() == '18' || ctArmor1TypeCombo.getValue() == '19'){
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(2));
									}else if(ctArmor1TypeCombo.getValue() == '20'){
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
										ctArmorSetStore.remove(ctArmorSetStore.getAt(1));
									}

								}
								setDescriptoin();
							}
						}
					}
				});
				
				ctArmorSetCombo = new Ext.form.ComboBox({
					fieldLabel: armorMessage.get('ui.armor.set'),
					id: 'ctArmorSet',
					name: 'ctArmorSet',
					editable: false,
					valueField: 'code',
				    store: ctArmorSetStore,
				    displayField:'description',
				    triggerAction: 'all',
				    allowBlank: false,
				    hideLabel: true,
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					anchor: '80%',
					listeners: {
						select: {
							fn: function (thisComb, record,index){
								setReference();
								setDescriptoin();
							}
						}
					}
				});
				
				ctJaugeCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.jauge'),
					id: 'ctJauge',
					name: 'ctJauge',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					valueField: 'code',
				    store: ctJaugeStore,
				    displayField:'description',
				    triggerAction: 'all',
				    anchor: '90%',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
					listeners: {
						select: {
							fn: function (thisComb, record,index){
								setReference();
							}
						}
					}
				});
                
                var armorForm = new Ext.FormPanel({
					fileUpload: true,
                    labelAlign: 'left',
                    url: '../../servlet/BiArmorServlet?action=1',
                    frame: true,
                    title: armorMessage.get('ui.armor.edittitle'),
                    bodyStyle: 'padding:5px 5px 5px 5px;margin-top: 2px;',
                    width: '100%',
                    labelWidth: 95,
                    reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    },{
						name: 'reference',
						mapping: 'reference'
					},{
						name: 'referenceIndex',
						mapping: 'referenceIndex'
					},{
						name: 'ctArmorType',
						mapping: 'ctArmorType'
					},{
						name: 'ctArmor1Type',
						mapping: 'ctArmor1Type'
					},{
						name: 'armorTypeE',
						mapping: 'armorTypeE'
					},{
						name: 'ctArmorSet',
						mapping: 'ctArmorSet'
					},{
						name: 'ctJauge',
						mapping: 'ctJauge'
					},{
						name: 'armor',
						mapping: 'armor'
					},{
						name: 'photo1Name',
						mapping: 'photo1Name'
					},{
						name: 'photo2Name',
						mapping: 'photo2Name'
					},{
						name: 'photo3Name',
						mapping: 'photo3Name'
					},{
						name: 'photo4Name',
						mapping: 'photo4Name'
					},{
						name: 'commentFr',
						mapping: 'commentFr'
					},{
						name: 'commentCn',
						mapping: 'commentCn'
					},{
						name: 'commentEn',
						mapping: 'commentEn'
					}]),
                    items: [{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                    },{
                        id: 'referenceIndex',
                        name: 'referenceIndex',
                        xtype: 'hidden'
                    },{
                        id: 'photo1Name',
                        name: 'photo1Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo2Name',
                        name: 'photo2Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo3Name',
                        name: 'photo3Name',
                        xtype: 'hidden'
                    },{
                        id: 'photo4Name',
                        name: 'photo4Name',
                        xtype: 'hidden'
                    }, {
						layout: 'column',
						items: [{
							columnWidth:.25,
			                layout: 'form',
							items: [ctArmorTypeCombo]
						},{
							columnWidth:.25,
			                layout: 'form',
							items: [ctArmor1TypeCombo]
						},{
							columnWidth:.15,
			                layout: 'form',
							items: [{
								name: 'armorTypeE',
		                        id: 'armorTypeE',
		                        xtype: 'textfield',
		                        hideLabel:true,
		                        anchor: '86%',
		                        allowBlank: false,
		                        emptyText: 'Eg: 10/5 or 4/8',
		                        disabled: true,
		                        blankText: message.get('message.edit.noblank'),
		                        maxLength: 64,
		                        validator: function(){
		                        	var value = this.getValue();
		                        	var vArray = value.split('/');
		                        	if(vArray.length != 2)
			                        	return false;
									
									var patrn=/^\d+$/;
									if(patrn.test(vArray[0]) && patrn.test(vArray[1]))
										return true;
								}
							}]
						},{
							columnWidth:.15,
			                layout: 'form',
							items: [ctArmorSetCombo]
						},{
							columnWidth:.2,
			                layout: 'form',
							items: [ctJaugeCombo]
						}]
                    },{
						name: 'description',
                        id: 'description',
                        fieldLabel: message.get('message.edit.description'),
                        xtype: 'textfield',
                        anchor: '86%',
                        readOnly: true,
                        blankText: message.get('message.edit.noblank'),
                        maxLength: 64
					},{
						name: 'reference',
                        id: 'reference',
                        fieldLabel: message.get('message.edit.reference'),
                        xtype: 'textfield',
                        anchor: '86%',
                        allowBlank: false,
                        blankText: message.get('message.edit.noblank'),
                        maxLength: 64
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo1',
						name: 'photo1',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '1',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						xtype: 'fileuploadfield',
						width: '80%',
			            id: 'photo2',
						name: 'photo2',
			            emptyText: message.get('message.edit.selectimage'),
			            fieldLabel: message.get('message.edit.photo') + '2',
			            buttonCfg: {
			                text: '',
			                iconCls: 'uploadIcon'
		            	}
					},{
						fieldLabel: message.get('message.edit.descriptionfr'),
                        name: 'commentFr',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					},{
						fieldLabel: message.get('message.edit.descriptioncn'),
                        name: 'commentCn',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					},{
						fieldLabel: message.get('message.edit.descriptionen'),
                        name: 'commentEn',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
					}],
                    
                    buttons: [{
                        text: message.get('message.edit.save'),
                        handler: function(){
                            if (armorForm.getForm().isValid()) {
                            	
                            	if(idValue == null){
                            		setReference();
                            	}
                            	
								document.getElementsByName('ctArmorType')[0].value = ctArmorTypeCombo.getValue();
								document.getElementsByName('ctArmor1Type')[0].value = ctArmor1TypeCombo.getValue();
								document.getElementsByName('ctArmorSet')[0].value = ctArmorSetCombo.getValue();
								document.getElementsByName('ctJauge')[0].value = ctJaugeCombo.getValue();
							
                                armorForm.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
										document.getElementById('photo1-file').value = null;
										document.getElementById('photo2-file').value = null;
                                        armorForm.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
                    }, {
                        text: message.get('message.edit.reset'),
                        handler: function(){
                            armorForm.getForm().reset();
                        }
                    }, {
                        text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'armor_list.html?startPage=' + startPage;
                            }
                            else {
                                window.location = 'armor_list.html';
                            }
                        }
                    }]
                })
                
                armorForm.render('armorDiv');
				
				new Ext.Resizable('customImg', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                new Ext.Resizable('customImg1', {
                    wrap: true,
                    pinned: true,
                    dynamic: true,
                    handles: 'all',
                    draggable: true
                });
                
                if (idValue != null) {
                    document.getElementById('id').value = idValue;
                    armorForm.getForm().load({
                        url: '../../servlet/BiArmorServlet?action=3&id=' + idValue,
                        waitMsg: Ext.LoadMask.prototype.msg,
                        success: function(form, action){
                            document.getElementById('customImg').src =  '../../_temp/' + document.getElementById('photo1Name').value;
							document.getElementById('customImg1').src =  '../../_temp/' + document.getElementById('photo2Name').value;
							//document.getElementById('customImg2').src =  '../../_temp/' + document.getElementById('photo3Name').value;
							//document.getElementById('customImg3').src =  '../../_temp/' + document.getElementById('photo4Name').value;
							var ctArmorSet = ctArmorSetCombo.getValue();
							//alert(ctArmorSet);
							//return;
							var ctArmor1Type =  ctArmor1TypeCombo.getValue();
							ctArmorTypeCombo.fireEvent('select', ctArmorTypeCombo);
							
							ctArmor1TypeCombo.setValue(ctArmor1Type);
							ctArmor1TypeCombo.fireEvent('select', ctArmor1TypeCombo);
							ctArmorSetCombo.setValue(ctArmorSet);
							setDescriptoin();
                        }
                    });
                }
                
            });
        </script>
    </head>
    <body>
        <div id="armorDiv">
        </div>
		<img id="customImg" src="../../_temp/noimage.gif" style="position:absolute;left: 20%;width: 250px;" onclick="openImageViewer(this.src);"/>
		<img id="customImg1" src="../../_temp/noimage.gif" style="position:absolute;left: 60%;width: 250px;" onclick="openImageViewer(this.src);"/>
    </body>
</html>
